package org.hit.burkun.obo.model;

import javax.annotation.Nonnull;

public class Relationship {
	public enum RELATION {
		IS_A("is_a"), PART_OF("part_of"), POSITIVELY_REGULATES(
				"positively_regulates"), REGULATES("regulates"), NEGATIVELY_REGULATES(
				"negatively_regulates"), HAS_PART("has_part");
		@Nonnull
		private final String tag;

		RELATION(@Nonnull String tag) {
			this.tag = tag;
		}

		/** @return tag */
		@Nonnull
		public String getTag() {
			return tag;
		}

		@Override
		public String toString() {
			return tag;
		}

		public static RELATION getEnum(String tag) {
			if (tag.equals(IS_A.getTag())) {
				return IS_A;
			} else if (tag.equals(PART_OF.getTag())) {
				return PART_OF;
			} else if (tag.equals(POSITIVELY_REGULATES.getTag())) {
				return POSITIVELY_REGULATES;
			} else if (tag.equals(REGULATES.getTag())) {
				return REGULATES;
			} else if (tag.equals(NEGATIVELY_REGULATES.getTag())) {
				return NEGATIVELY_REGULATES;
			} else if (tag.equals(HAS_PART.getTag())) {
				return HAS_PART;
			} else {
				// not define relation
				return null;
			}
		}
	}

	private RELATION relation;

	private String relationStr;

	/**
	 * 权宜之计，防止relation为定义出错
	 * 
	 * @return
	 */
	public String getRelationStr() {
		return relationStr;
	}

	public RELATION getRelation() {
		return relation;
	}

	public void setRelation(RELATION relation) {
		this.relation = relation;
		this.relationStr = relation.getTag();
	}

	public void setRelation(String relStr) {
		this.relation = RELATION.getEnum(relStr);
		if (this.relation != null) {
			relationStr = this.relation.getTag();
		} else {
			relationStr = relStr;
		}
	}

	private String termID;

	public String getTermID() {
		return termID;
	}

	public void setTermID(String termID) {
		this.termID = termID;
	}

	@Override
	public String toString() {
		return "relation:" + relation.getTag() + " termID:" + termID;
	}
}
